package com.lihaozhe.config;

import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Bean;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
// import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

/**
 * @author 李昊哲
 * @version 1.0
 * 2021/12/10 下午1:38
 */
@RequiredArgsConstructor
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
    // private final UserDetailsService userDetailsService;
    // @Override
    // protected void configure(AuthenticationManagerBuilder auth) throws Exception {
         // 密码处理对象
        // PasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
        // 密码加密
        // String password = passwordEncoder.encode("123456");
        // 将账号-密码-角色存储在内存中
        // auth.inMemoryAuthentication().withUser("lhz").password(password).roles("admin");
        // auth.userDetailsService(userDetailsService).passwordEncoder(new BCryptPasswordEncoder());
    // }

    @Bean
    public PasswordEncoder newPasswordEncoder() {
        return new BCryptPasswordEncoder();
    }
}